﻿#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
long long huiwen(long long M, int N)//倒置M
{
    long long out = 0;
    if (N < 11)
    {
        while (M != 0)
        {
            out = 10 * out + M % 10;
            M /= 10;
        }
    }
    else {
        while (M != 0)
        {
            out = 16 * out + M % 16;
            M /= 16;
        }
    }
    return out;
}
long long sum(long long M, long long huiw_M, int N)//M与倒置数相加
{
    int num = 0, jin = 0, i = 0;
    long long out = 0;

    if (N < 11)
    {
        while (M != 0)
        {
            num = M % 10 + huiw_M % 10 + jin;
            out = out + num % N * pow(10, i);
            jin = num / N;
            M /= 10;
            huiw_M /= 10;
            i++;
        }
    }
    else {
        while (M != 0)
        {
            num = M % 16 + huiw_M % 16 + jin;
            out = out + num % N * pow(16, i);
            jin = num / N;
            M /= 16;
            huiw_M /= 16;
            i++;
        }
    }
    if (N < 11)
        out = out + jin * pow(10, i);
    else
        out = out + jin * pow(16, i);
    return out;
}
int main() {
    int N;
    scanf("%d", &N);
    long long M;
    if (N < 11)
        scanf("%lld", &M);
    else
        scanf("%llX", &M);
    int step = 0, flag = 1;
    while (M != huiwen(M, N))//判断回文数
    {
        if (step > 30)
        {
            flag = 0;
            break;
        }
        M = sum(M, huiwen(M, N), N);
        step++;
    }
    if (flag == 1)
    {
        printf("STEP=%d\n", step);
    }
    else {
        printf("Impossible!\n");
    }
    return 0;
}